package gcosc.fun.hly.fastsso.controller;


import gcosc.fun.hly.fastsso.domain.Bo.PageQuery;
import gcosc.fun.hly.fastsso.domain.SsoRole;
import gcosc.fun.hly.fastsso.result.Result;
import gcosc.fun.hly.fastsso.result.TableDataInfo;
import gcosc.fun.hly.fastsso.service.ISsoRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 角色
 *
 * @author ruoyi
 * @date 2023-12-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/sso/role")
public class SsoRoleController{

    private final ISsoRoleService iSsoRoleService;

    /**
     * 查询角色列表
     */
    @GetMapping("/list")
    public TableDataInfo<SsoRole> list(SsoRole bo, PageQuery pageQuery) {
        return iSsoRoleService.queryPageList(bo, pageQuery);
    }

    /**
     * 全部角色列表
     */
    @GetMapping("/all")
    public Result all(SsoRole bo) {
        return Result.ok(iSsoRoleService.queryList(bo));
    }

    /**
     * 导出角色列表
     */
//    @PostMapping("/export")
//    public void export(SsoRoleBo bo, HttpServletResponse response) {
//        List<SsoRoleVo> list = iSsoRoleService.queryList(bo);
//        ExcelUtil.exportExcel(list, "角色", SsoRole.class, response);
//    }

    /**
     * 获取角色详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public Result<SsoRole> getInfo(@PathVariable Long id) {
        return Result.ok(iSsoRoleService.queryById(id));
    }

    /**
     * 新增角色
     */
    @PostMapping()
    public Result<Void> add(@RequestBody SsoRole bo) {
        return Result.ok(iSsoRoleService.insertByBo(bo));
    }

    /**
     * 修改角色
     */
    @PutMapping()
    public Result<Void> edit(@RequestBody SsoRole bo) {
        return Result.ok(iSsoRoleService.updateByBo(bo));
    }

    /**
     * 删除角色
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public Result<Void> remove(@PathVariable Long[] ids) {
        return Result.ok(iSsoRoleService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
